package com.cskaoyan.controller.promotion_controller;

import com.cskaoyan.bean.Ad;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.params.BaseParam;
import com.cskaoyan.bean.vo.promotion_vo.AdCreateVO;
import com.cskaoyan.bean.vo.promotion_vo.AdUpdateVO;
import com.cskaoyan.bean.vo.promotion_vo.AdVO;
import com.cskaoyan.service.promotion_service.AdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description：
 * @author: 曹旭
 * @date: 2022/5/7 13:43
 */
@RestController
@RequestMapping("admin/ad")
public class AdController {
    @Autowired
    AdService adService;

    /**
     * 显示广告信息
     * @param baseParam
     * @param name
     * @param content
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo list(BaseParam baseParam,String name,String content){
        AdVO adVo = adService.list(baseParam,name,content);
        return BaseRespVo.ok(adVo);
    }

    /**
     * 增加广告
     * TODO 图片上传如何实现？阿里云？
     * @param ad
     * @return
     */
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Ad ad){
        AdCreateVO adCreateVO = adService.create(ad);
        return BaseRespVo.ok(adCreateVO);
    }

    /**
     * 更新广告
     * @param ad
     * @return
     */
    @RequestMapping("update")
    public BaseRespVo updateAD(@RequestBody Ad ad){
        AdUpdateVO adUpdateVO = adService.updateAD(ad);
        return BaseRespVo.ok(adUpdateVO);
    }

    /**
     * 删除广告
     * @param ad
     * @return
     */
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Ad ad){
        adService.delete(ad);
        return BaseRespVo.ok(null);
    }
}
